package cn.ffcs.unm.abroad.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.abroad.dao.AbroadDao;
import cn.ffcs.unm.abroad.model.Abroad;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("abroadDao")
public class AbroadDaoImpl extends BaseDaoImpl implements AbroadDao {
	@Override
	public PageInfo queryAbroadPage(Abroad abroad, int currentPage, int pageSize) {
		StringBuilder sql = new StringBuilder();
		sql.append(" SELECT * FROM  VIEW_HI_PSNDOC_ABROAD v WHERE 1 = 1 ");
		
		List<Object> params = new ArrayList<Object>();
			if (abroad != null) {
				if(!StrUtil.isNullOrEmpty(abroad.getMonthId())) {
					sql.append(" AND V.monthId = ? ");
					params.add(abroad.getMonthId());
				}
				if (!StrUtil.isNullOrEmpty(abroad.getName())) {
					sql.append(" AND V.name like ?");
					params.add("%"
							+ StringEscapeUtils.escapeSql(abroad.getName())
							+ "%");
				}
				if (!StrUtil.isNullOrEmpty(abroad.getAbroadOut())) {
					sql.append(" and V.ABROADOUT like ?");
					params.add("%"
							+ StringEscapeUtils.escapeSql(abroad.getAbroadOut())
							+ "%");
				}
				if (!StrUtil.isNullOrEmpty(abroad.getAbroadUnit())) {
					sql.append(" and V.ABROADUNIT like ?");
					params.add("%"
							+ StringEscapeUtils.escapeSql(abroad
									.getAbroadUnit()) + "%");
				}
			return super.jdbcFindPageInfo(sql.toString(), params, currentPage,
					pageSize, Abroad.class);
		}
		return null;
	}

}
